/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package ChatNI;

import common.Message;
import ChatNI.*;
import MVC.*;
import InterfaceUser.*;

import java.net.UnknownHostException;
import java.util.LinkedList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * TraiteMessage
 * Class specific for treating the received messages
 * This class inherits a thread
 * @author Duy Duc, Metangmo
 */
public class TraiteMessage extends Thread  {
    
    private ChatController controller;
    private LinkedList<Message> fileMessage;

    public TraiteMessage(ChatController controller,LinkedList<Message> fileMessage) {
        super();
        this.controller = controller;
        this.fileMessage = fileMessage;
    }
    
     public void run() {
        
        while (true) {
            //There aren't any messages in the queue of treatement
            if (fileMessage.isEmpty()){
                
            }
            else {
               //The message in the top of the queue is removed and sent to the ChatController
                Message mess = fileMessage.removeFirst();
                try {
                    // The ChatController takes care of the received message
                    controller.performReceiveMessage(mess);
                } catch (UnknownHostException ex) {
                    Logger.getLogger(TraiteMessage.class.getName()).log(Level.SEVERE, null, ex);
                }
                
            }
        }
    }
    
    
}
